﻿Imports log4net
Imports System.Data.OracleClient
Imports System.Configuration
Imports System.Threading.Tasks

Public Class LogHelp

    Public Shared loginfo As ILog = log4net.LogManager.GetLogger("loginfo")
    Public Shared logerror As log4net.ILog = log4net.LogManager.GetLogger("logerror")
    Public Shared logoracle As ILog = log4net.LogManager.GetLogger("logoracle") 'add:Wangjh 20180411
    Private Shared myLog As ILog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
    Private Shared IsLog As String = ConfigurationManager.AppSettings("IsOracleLog").ToString()
    Public Shared Sub SetConfig()
        log4net.Config.XmlConfigurator.Configure()
    End Sub

    Public Shared Sub WriteLog(ByVal strInfo As String)
        loginfo.Info(strInfo)
    End Sub

    Public Shared Sub WriteError(ByVal strInfo As String, ByVal e As Exception)
        logerror.Error(strInfo, e)
    End Sub
    ''' <summary>
    ''' 日志写入到数据库
    ''' add:Wangjh 20180411
    ''' </summary>
    ''' <param name="strInfo"></param>
    ''' <param name="args"></param>
    ''' <remarks></remarks>
    Public Shared Sub WriteOrcale(ByVal strInfo As String, ByVal ParamArray args As Object())
        If IsLog <> "是" Then
            Return
        End If
        Dim t1 As Task = New Task(Sub()
                                      logoracle.InfoFormat(strInfo, args)
                                  End Sub)
        t1.Start()

    End Sub
    ''' <summary>
    ''' 错误信息日志写入到数据库
    ''' add:Wangjh 20180411
    ''' </summary>
    ''' <param name="strInfo"></param>
    ''' <param name="args"></param>
    ''' <remarks></remarks>
    Public Shared Sub WriteOrcaleError(ByVal strInfo As String, ByVal ParamArray args As Object())
        If IsLog <> "是" Then
            Return
        End If
        Dim t1 As Task = New Task(Sub()
                                      logoracle.ErrorFormat(strInfo, args)
                                  End Sub)
        t1.Start()
    End Sub
    ''' <summary>
    ''' 转化传参的sql
    ''' add:Wangjh 20180529
    ''' </summary>
    ''' <param name="strSql"></param>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function TranferSql(ByVal strSql As String, ByVal ParamArray para As OracleParameter()) As String
        For Each eachPara As OracleParameter In para
            strSql = strSql.Replace(eachPara.ParameterName, "'" & eachPara.Value.ToString & "'")
        Next
        Return strSql
    End Function
End Class
